﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using School.Entities;
using School.Teaching;
using System.Drawing;
namespace School.Pages.Teaching
{
    public partial class TE_Grad_Success_Policy : System.Web.UI.Page
    {
        private static SchoolEntities db = new SchoolEntities();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!this.Page.IsPostBack)
                FillControls();

        }
        private void FillControls()
        {
            ddlCampus.DataSource = School.Uniform.PayOrder.AllCampus();
            ddlCampus.DataBind();
        }
        private void ddlBind(DropDownList ddl)
        {
            ddl.Items.Clear();
            ddl.Items.Insert(0, new ListItem("اختيار", "0"));
            ddl.DataBind();
        }
        protected void ddlCertificate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlCertificate.SelectedValue != "0")
            {
                ddlStadge.DataSource = School.Uniform.PayOrder.GetStadgeByCertificate(int.Parse(ddlCertificate.SelectedValue));
                ddlBind(ddlStadge);
            }
        }
        protected void ddlStadge_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlStadge.SelectedValue != "0")
            {
                ddlGrade.DataSource = School.Uniform.PayOrder.GetGradeByStadge(int.Parse(ddlStadge.SelectedValue));
                ddlBind(ddlGrade);
            }
        }
        protected void ddlCampus_TextChanged(object sender, EventArgs e)
        {
            if (ddlCampus.SelectedValue != "0")
            {
                ddlCertificate.DataSource = School.Uniform.PayOrder.GetCertificateByCamp(int.Parse(ddlCampus.SelectedValue));
                ddlBind(ddlCertificate);
            }
        }
        private void ddlBind(DropDownList ddl, object o)
        {
            ddl.DataSource = o;
            ddl.Items.Clear();
            ddl.Items.Insert(0, new ListItem("اختيار", "0"));
            ddl.DataBind();
        }
        protected void btndisplay_Click(object sender, EventArgs e)
        {
            gvsubjectBind();
        }
        private void gvsubjectBind()
        {
            var q = OfflineExam.Get_Subject_By_Grad(Convert.ToInt32(ddlGrade.SelectedValue));
            gvsubject.DataSource = q;
            gvsubject.DataBind();
            if (gvsubject.Rows.Count > 0)
                fgv.Visible = true;
            else
                fgv.Visible = false;
        }

        /*protected void btnSave_Click(object sender, EventArgs e)
        {
          bool re=  OfflineExam.Delete_Grad_Success_Policy(Convert.ToInt32(ddlGrade.SelectedValue));
          if (re)
          {
              foreach (GridViewRow row in gvsubject.Rows)
              {
                  int id = Convert.ToInt32(gvsubject.DataKeys[row.RowIndex].Value.ToString());
                  RadioButtonList rdbtype = (RadioButtonList)row.FindControl("rdbtype");
                  re = OfflineExam.Add_Grad_Success_Policy(id, Convert.ToInt32(ddlGrade.SelectedValue), Convert.ToByte(rdbtype.SelectedValue));
              }

              if(re)
              { lbltst.ForeColor = Color.Green;
                lbltst.Text = "تمت الاضافة بنجاح";
              
              }
              else
              {
                              lbltst.ForeColor = Color.Red;
                lbltst.Text = "لم تتم عملية الاضافة..حاول مرة اخري";
              }
          }
          else
          {                 lbltst.ForeColor = Color.Red;
                lbltst.Text = "لم تتم عملية الاضافة..حاول مرة اخري";
          }      
            lbltst.Visible = true;

        }*/
    }
}

